package com.itheima.exerciseTest.method40_49.method40;

        import java.io.IOException;
        import java.io.InputStream;
        import java.lang.reflect.Field;
        import java.lang.reflect.InvocationTargetException;
        import java.lang.reflect.Method;
        import java.util.Properties;
        import java.util.Scanner;

public class Demo {
    public static void main(String[] args) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
        Scanner sc = new Scanner(System.in);
        // 获取系统类加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();

        // 加载prop.properties配置文件
        InputStream is = systemClassLoader.getResourceAsStream("com\\itheima\\exerciseTest\\method40_49\\method40\\prop.properties");

        // 将配置文件中的信息读取到集合中
        Properties prop = new Properties();
        prop.load(is);
        is.close();

        // 获取Class类对象
        Class className = Class.forName(prop.getProperty("className"));

        // 获取构造类对象
        Person p = (Person) className.newInstance();

        // 设置属性值
        Field fieldName = className.getDeclaredField(prop.getProperty("fieldName"));
        fieldName.setAccessible(true);
        System.out.println("请输入id");
        fieldName.set(p,sc.next());
        System.out.println("请输入姓名");
        p.setName(sc.next());
        System.out.println("请输入年龄");
        p.setAge(sc.nextInt());
        System.out.println("请输入性别");
        p.setGender(sc.next());

        // 获得方法
        Method method = className.getDeclaredMethod(prop.getProperty("methodName"));

        // 运行方法
        method.invoke(p);
    }
}
